<template>
  <div>
    <div slot="header" class="cardClass_header">
      <h3>饲养分析</h3>
      <div>
        <el-button
          size="mini"
          type="success"
          icon="el-icon-plus"
          @click="open('创建饲养记录')"
          >新增</el-button
        >
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-search"
          @click="searchHidden()"
          >搜索</el-button
        >
      </div>
    </div>
    <!-- 查询开始 -->
    <el-collapse-transition>
      <el-form
        :model="ruleForm"
        :inline="true"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        v-if="hidden"
      >
        <el-form-item label="管理号：" prop="key">
          <el-select
            v-model="ruleForm.key"
            placeholder="请选择查询字段"
            size="small"
          >
            <el-option
              v-for="item in keyOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
       <el-form-item label="值：" prop="value">
          <el-input
            v-model="ruleForm.value"
            placeholder="请输入值"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            size="small"
            icon="el-icon-search"
            >查询</el-button
          >
          <el-button
            @click="resetForm('ruleForm')"
            size="small"
            icon="el-icon-refresh"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-collapse-transition>
    <el-table
      :data="tableData"
      style="width: 100%; text-align: center; margin-top: 20px; padding: 10px"
    >
      <el-table-column label="项目" width="200" align="center" prop="xiangmu">
      </el-table-column>
      <el-table-column
        prop="chuqishu"
        label="初期数"
        width="100"
        align="center"
      ></el-table-column>
      <el-table-column label="本月增加" align="center">
        <el-table-column
          prop="diaobodiaoru"
          label="调拨调入"
          width="80"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="zhuanqunzhuanru"
          label="转群转入"
          width="80"
          align="center"
        ></el-table-column>
        <el-table-column label="购入" width="100" align="center">
          <el-table-column label="外部购入" width="100" align="center">
            <el-table-column label="购入" align="center" prop="gouru">
            </el-table-column>
            <el-table-column label="置换" align="center" prop="zhihuan">
            </el-table-column>
          </el-table-column>
          <el-table-column label="内部购入" align="center" prop="zhihuan">
          </el-table-column>
        </el-table-column>
        <el-table-column label="出生" width="80" align="center" prop="chusheng">
        </el-table-column>
        <el-table-column
          label="调拨调入"
          width="80"
          align="center"
          prop="diaobodiaoru"
        >
        </el-table-column>
        <el-table-column
          label="转群转出"
          width="80"
          align="center"
          prop="zhuanqunzhaunchu"
        >
        </el-table-column>
        <el-table-column label="小计" width="80" align="center" prop="xiaoji">
        </el-table-column>
      </el-table-column>
      <el-table-column label="本月销售" align="center">
        <el-table-column label="正常销售" align="center">
          <el-table-column label="内部销售" align="center" prop="neibuxiaoshou">
          </el-table-column>
          <el-table-column label="外部销售" width="100" align="center">
            <el-table-column label="销售" align="center" prop="xiaoshou">
            </el-table-column>
            <el-table-column label="置换" align="center" prop="zhihuan2">
            </el-table-column>
          </el-table-column>
        </el-table-column>
        <el-table-column label="销售" width="100" align="center">
          <el-table-column
            label="24小时非留养"
            align="center"
            prop="feiliuyang"
          >
          </el-table-column>
          <el-table-column
            label="当期出生当期死亡"
            align="center"
            prop="dangqisiwang"
          >
          </el-table-column>
        </el-table-column>
      </el-table-column>

      <el-table-column label="操作" align="center" width="220">
        <template slot-scope="scope">
          <el-button
            type="warning"
            size="mini"
            icon="el-icon-edit"
            @click="open('修改饲养记录', scope.row)"
            >修改</el-button
          >
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="del(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <addfeedingAnalysis ref="addfeedingAnalysisref"> </addfeedingAnalysis>
  </div>
</template>

<script>
import {
  queryfeedinganalysis,
  deletefeedinganalysis,
} from "@/apis/dataSreening/feedingAnalysis";
import addfeedingAnalysis from '@/components/employee/addfeedingAnalysis'
export default {
  components:{
addfeedingAnalysis
  },
  data() {
    return {
      ruleForm: {
        key: "xiangmu",
        value: "",
        flag: 0,
        pageNum: 1,
        pageSize: 10,
      },
      hidden: false, // 控制搜索表单显示状态
      tableData: [],
      keyOptions: [
        { value: "xiangmu", label: "项目" },
        { value: "chuqishu", label: "初期数" },
      ],
    };
  },
  created() {
    this.search();
  },
  methods: {
    // 搜索隐藏
    searchHidden() {
      this.hidden = !this.hidden;
    },
    // 新增/修改弹窗
    open(title, row) {
      this.$refs.addfeedingAnalysisref.show(title, row);
    },
    //搜索方法
    search() {
      const _this = this;
      _this.loading = true;
      queryfeedinganalysis(_this.ruleForm).then((res) => {
        _this.tableData = res.data;
        _this.total = res.total;
        _this.loading = false;
      });
    },
    //搜索
    submitForm(formName) {
      const _this = this;
      _this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.ruleForm.pageNum = 1; // 查询重置页数
          _this.search(_this.ruleForm);
        }
      });
    },
    // 重置
    resetForm(formName) {
      let _this = this;
      this.$refs[formName].resetFields();
      this.search(_this.ruleForm);
      this.ruleForm.pageNum = 1; // 查询重置页数
    },
   
    // 删除
    del(row) {
      console.log(row);
      const _this = this;
      _this
        .$confirm("确认删除数据“" + row.xiangmu + "”吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          deletefeedinganalysis(row.id).then(function (res) {
            if (res.code === 0) {
              _this.$message({
                type: "success",
                message: "数据“" + row.xiangmu + "”" + res.msg,
              });
              _this.search();
              _this.ruleForm.pageNum = 1; // 查询重置页数
            } else {
              _this.$message({
                type: "error",
                message: "数据“" + row.xiangmu + "”" + res.msg,
              });
            }
          });
        })
        .catch(() => {});
    },
    // 分页
    changePage(pageNum) {
      this.ruleForm.pageNum = pageNum;
      this.search();
    },
  },
};
</script>

<style scoped>
.header {
  display: flex;
  align-items: center;
}
</style>